package com.job.tencent;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @ClassName: test.Tencent4
 * @Description:
 * @Author: 12071
 * @Date: 2022/4/24 21:03
 */
public class Tencent5 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt(); // 现金
        int[] price = new int[n];
        for (int i = 0; i < n; i++) {
            price[i] = sc.nextInt();
        }
        long[][] dp = new long[n+2][n+2];
        for (int i = 0; i < n; i++) {
            Arrays.fill(dp[i],Long.MIN_VALUE);
        }
        dp[0][0] = m;
        int x =0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <=i+1; j++) {
                dp[i+1][j] = Math.max(dp[i+1][j], dp[i][j]);
                if(j>0 && dp[i][j-1]>=price[i]){
                    x = Math.max(x,j);
                    dp[i+1][j] = Math.max(dp[i+1][j], dp[i][j-1] - price[i]);
                }
                dp[i+1][j] = Math.max(dp[i+1][j], dp[i][j+1]+price[i]);
            }
        }
        long res =0;
        for (int i = 0; i <= x + 1; i++) {
            res = Math.max(res, dp[n][i]+(long)(i) * price[n-1]);
        }
        System.out.println(res);
    }
}
